using System;

namespace Webshop20.Domain.Shared.Products.Core
{
    [Serializable]
    public class Discount
    {
        private const decimal ZERO_DISCOUNT = 0;
        public virtual int DiscountInPercent { get; private set; }
        public virtual DateTime EndTime { get; private set; }
        public virtual DateTime StartDate { get; private set; }

        public Discount(){}

        public Discount(int discountInPercent, DateTime endTime, DateTime startDate)
        {
            DiscountInPercent = discountInPercent;
            StartDate = startDate;
            EndTime = endTime;
        }

        public virtual decimal Calculate(decimal price, DateTime calculationDate)
        {
            if(StartDate <= calculationDate && calculationDate <= EndTime)
                return price * DiscountInPercent / 100;

            return ZERO_DISCOUNT;
        }
    }
}